# coding=utf-8
a = input().split(' ')
allmoney = a[0]
n = a[1]
things = []
for i in range(int(n)):
    item = input().split(' ')
    item = [int(x) for x in item]
    things.append(item)
